//
//  PromotionVC.m
//  TT
//
//  Created by Lenny on 16/4/18.
//  Copyright © 2016年 Lenny. All rights reserved.
//

#import "PromotionVC.h"
//views
#import "PromotionCell.h"
#import "PromotionTopV.h"

@interface PromotionVC ()<UICollectionViewDataSource,UICollectionViewDelegate,CellProtocol>
{
    CGFloat _topHigh,_cellHigh,_betweenWide;
    NSString *_cellR;
}

@property(nonatomic,strong)PromotionTopV *topV;
@property(nonatomic,strong)UICollectionView *contentCV;

@end

@implementation PromotionVC

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = WL_Back_Gray_Color;
    
    [self setData];
    [self UI];
    [self eventMothed];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - delegate motheds

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    PromotionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:_cellR forIndexPath:indexPath];
    cell.delegate = self;
    return cell;
}

#pragma mark - cell delegate 

- (void)cellProtocol:(id)cell withDic:(id)dic {
    
    NSLog(@"%@",cell);
}

#pragma mark - event motheds 

- (void)eventMothed {
    
    [self.topV addEvent:^(UIButton *btn) {
       
        NSLog(@"%ld",btn.tag);
    }];
}

#pragma mark - private motheds
- (void)setData {
    
    _topHigh = 50;
    _cellHigh = 90;
    _betweenWide = 10;
    _cellR = @"promotionCell";
}

- (void)UI {
    
    [self.view addSubview:self.topV];
    [self.view addSubview:self.contentCV];
    
    
    __weak typeof(self) weakSelf = self;
    
    [self.topV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(_topHigh);
    }];
    
    [self.contentCV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(weakSelf.topV.mas_bottom);
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
    }];
    
    [self.topV addUI];
}

#pragma mark - setters and getters
- (PromotionTopV *)topV {
    
    if (_topV == nil) {
        
        _topV = [[PromotionTopV alloc] init];
    }
    return _topV;
}

- (UICollectionView *)contentCV {
    
    if (_contentCV == nil) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(k_screen_w - 2 * _betweenWide, _cellHigh);
        _contentCV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _contentCV.backgroundColor = [UIColor whiteColor];
        _contentCV.delegate = self;
        _contentCV.dataSource = self;
        [_contentCV registerClass:[PromotionCell class] forCellWithReuseIdentifier:_cellR];
        _contentCV.contentInset = UIEdgeInsetsMake(_betweenWide, _betweenWide, _betweenWide, _betweenWide);
    }
    return _contentCV;
}

@end
